package control;

import java.awt.EventQueue;

import javax.swing.UIManager;

import model.emission_matrix.EmissionMatrix;
import model.trans_matrix.TransitionMatrix;

import view.AppWindow;

public class Application{
	/**
	 * Launch the application.
	 */	
	private int pathMatrixSize = 8;
	private AppWindow frame;
	private TransitionMatrix tranMatrix = new TransitionMatrix(pathMatrixSize);
	private EmissionMatrix emiMatrix = new EmissionMatrix(2,pathMatrixSize*pathMatrixSize);
	private int numberPlayers;
	private int numberExits;	
	private int pathNodesCounter=0;
	private static Application INSTANCE = null;	
	private Viterbi viterbi = new Viterbi();

	// Private constructor para el singleton
  private Application() {}

  // creador sincronizado para protegerse de instanciación múltiple 
  private synchronized static void createInstance() {
      if (INSTANCE == null) { 
          INSTANCE = new Application();
      }
  }
  
	public int getPathNodesCounter() {
		return pathNodesCounter;
	}

	public void setPathNodesCounter(int pathNodesCounter) {
		this.pathNodesCounter = pathNodesCounter;
	}

  public Viterbi getViterbi() {
		return viterbi;
	}

	public void setViterbi(Viterbi viterbi) {
		this.viterbi = viterbi;
	}

  public static Application getInstance() {
      createInstance();
      return INSTANCE;
  }
  	
	public int getPathMatrixSize() {
		return pathMatrixSize;
	}

	public void setPathMatrixSize(int pathMatrixSize) {
		Application.getInstance().pathMatrixSize = pathMatrixSize;
	}

	public AppWindow getFrame() {
		return frame;
	}

	public void setFrame(AppWindow frame) {
		Application.getInstance().frame = frame;
	}

	public TransitionMatrix getTranMatrix() {
		return tranMatrix;
	}

	public void setTranMatrix(TransitionMatrix tranMatrix) {
		Application.getInstance().tranMatrix = tranMatrix;
	}

	public EmissionMatrix getEmiMatrix() {
		return emiMatrix;
	}

	public void setEmiMatrix(EmissionMatrix emiMatrix) {
		Application.getInstance().emiMatrix = emiMatrix;
	}

	public int getNumberPlayers() {
		return numberPlayers;
	}

	public void setNumberPlayers(int numberPlayers) {
		Application.getInstance().numberPlayers = numberPlayers;
	}

	public int getNumberExits() {
		return numberExits;
	}

	public void setNumberExits(int numberExits) {
		Application.getInstance().numberExits = numberExits;
	}

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					if(System.getProperty("os.name").toLowerCase().indexOf("win")>=0){
			      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");						
					}
					else{
						UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
					}
					Application app = getInstance();
					app.frame = new AppWindow();
					app.frame.setVisible(true);
					app.frame.setResizable(false);
					app.numberExits=0;
					app.numberPlayers=0;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
}
